package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JsonResult;
import cn.wolfcode.trip.base.util.UploadUtil;
import cn.wolfcode.trip.base.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/images")
public class ImageController {
    @Autowired
    private IUserService userService;
    @PostMapping
    public Map upload(MultipartFile file){  // 因为页面提交的是一个文件
        // 上传图片,保存到指定目录中
        Map<String, Object> map = new HashMap<>();
        try {
            String url = UploadUtil.upload(file,  UploadUtil.PATH+"/upload");
            map.put("status",1);
            map.put("url",url);
        }catch (Exception e){
            e.printStackTrace();
            map.put("status",0);
            map.put("msg","亲,上传失败!");
        }
        return map;
    }
}
